function result = template_canonical_correlation_analysis(data,refData,freq)
%---input---
%data:数据，行为数据点，列为通道
%refdata:参考信号，size1：数据点，列：频率
%freq：所有刺激频率
%nHarmonics：谐波次数
%---output---
%result：识别结果
data = data';
channels = 1:6;   %Pz-48, PO5, PO3, POz, PO4, PO6, O1, Oz, and O2

%% CCA Algorithm
bpData = data(:,channels);
cc=[0,0,0,0];
Kcc=[0,0,0,0];
KKcc=[1,1,1,1];
for j=1:length(freq)
    [~,~,D] = canoncorr(bpData, refData(:,j));
    cc(j)=sum(D);
end
cc=(cc-Kcc).*KKcc;
% target identification
result = find(cc==max(cc));
end

